package com.itcat.api;/*
 * @Author: gonhsl
 * @Date:2022-04-02-21:11
 * */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.SmsHomeBrandApi;
import com.itcat.mapper.SmsHomeBrandMapper;
import com.itcat.mysql.pojo.SmsHomeBrand;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class SmsHomeBrandApiImpl implements SmsHomeBrandApi {
    @Autowired
    private SmsHomeBrandMapper smsHomeBrandMapper;
    @Override
    public Page<SmsHomeBrand> list(Integer pageNum, Integer pageSize, String brandName, Integer recommendStatus) {
        Page<SmsHomeBrand> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<SmsHomeBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(brandName!=null,SmsHomeBrand::getBrandName,brandName)
                .eq(recommendStatus!=null,SmsHomeBrand::getRecommendStatus,recommendStatus);
        Page<SmsHomeBrand> brandPage = smsHomeBrandMapper.selectPage(page, wrapper);
        return brandPage;
    }

    @Override
    public void create(List<SmsHomeBrand> homeBrand) {
        for (SmsHomeBrand smsHomeBrand : homeBrand) {
            smsHomeBrandMapper.insert(smsHomeBrand);
        }
    }

    @Override
    public void delete(List<Integer> ids) {
        smsHomeBrandMapper.deleteBatchIds(ids);
    }

    @Override
    public void updateRecommendStatus(List<Integer> ids, Integer recommendStatus) {
        LambdaUpdateWrapper<SmsHomeBrand> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.in(SmsHomeBrand::getId,ids).set(SmsHomeBrand::getRecommendStatus,recommendStatus);
        SmsHomeBrand smsHomeBrand = new SmsHomeBrand();
        smsHomeBrand.setRecommendStatus(recommendStatus);
        smsHomeBrandMapper.update(smsHomeBrand,updateWrapper);
    }

    @Override
    public void updateSort(Integer id, Integer sort) {
        SmsHomeBrand smsHomeBrand = new SmsHomeBrand();
        smsHomeBrand.setId(id.longValue());
        smsHomeBrand.setSort(sort);
        smsHomeBrandMapper.updateById(smsHomeBrand);
    }
}
